#include<iostream>
#include<cstdio>
using namespace std;
const int N = 100;
int arr[N];
int	price[7] = { 7, 27, 41, 49, 63, 78, 108 };
int main()
{
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		scanf("%d", &n);
		int sum = 0;
		for (int i = 0; i < n; i++) {
			/*cin >> arr[i];*/
			scanf("%d", &arr[i]);
			sum += price[arr[i] - 1];
		}
		if (sum >= 120) {
			sum -= 50;
		}
		else if (sum >= 89) {
			sum -= 30;
		}
		else if (sum >= 69) {
			sum -= 15;
		}
		printf("%d\n", sum);
	}
	return 0;
}